<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>系统设置</title>
    <script src="/js/include.js"></script>
</head>
<body>
<div id="myapp">
    <el-form :model="editForm" :rules="rules" ref="editForm" label-width="100px" class="demo-editForm">
        <el-card class="box-card">
            <div class="text item">
                初始密码 <el-input v-model="editForm.initPassword" clearable size="mini" style="width: 200px;"></el-input>
            </div>
        </el-card>

        <el-card class="box-card">
            <div slot="header" class="clearfix">
                <span>警报邮箱</span>
                <el-button @click="addEmail()" type="success" icon="el-icon-circle-plus-outline" size="mini"></el-button>
            </div>
            <div class="text item">
                <template v-for="e in emails">
                    <div style="margin-top: 5px">
                        <el-input v-model="e.url" placeholder="邮箱" clearable size="mini" style="width: 200px;"></el-input>
                        <el-input v-model="e.name" placeholder="邮箱所属人" clearable size="mini" style="width: 200px;"></el-input>
                        <el-button @click="delEmail()" type="danger" icon="el-icon-delete" size="mini"></el-button>
                    </div>
                </template>
            </div>
        </el-card>

        <el-card class="box-card">
            <el-button type="primary" @click="submitForm">提 交</el-button>
        </el-card>


    </el-form>
</div>
</body>
<script>
    let vm = new Vue({
        el: '#myapp',
        data: {
            loading: false,
            editForm: {

            },
            emails: [],
            rules: {
                initPassword: [{required: true, trigger: 'blur', message: '初始密码不能为空'}],
            },

        },
        methods: {
            submitForm() {
                let that = this;
                myConfirm("确定提交？", function () {
                    showLoading("保存中....");
                    let email = JSON.stringify(that.emails);
                    let editForm = JSON.parse(JSON.stringify(that.editForm));
                    editForm.email = email;
                    let url = BASE_PATH + "/systemSetting/update";
                    myAjax({
                        type: "post",
                        url: url,
                        data: editForm,
                        isJson: true,
                        callback: function () {
                            hideLoading();
                            successMessage("提交成功！");
                        }
                    })
                });
            },
            loadData() {
                let that = this;
                myAjax({
                    type: "get",
                    url: BASE_PATH + "/systemSetting/get",
                    callback: function (data) {
                        that.editForm = data;
                        that.emails = JSON.parse(data.email);
                    }
                })
            },
            addEmail() {
                this.emails.push({url: "", name: ""});
            },
            delEmail(index) {
                this.emails.splice(index, 1);
            },
        },
        created: function () {
            this.loadData();
        },
    });
</script>
</html>
